semaphore is package{
  
  semaphore(Count) is {
    private var Lvl := Count;
    
    private lock is 1; -- value not important
    
    grab() do {
      -- logMsg(info,"grabbing, level=$Lvl");
      sync(lock){
        when Lvl>0 do {
          -- logMsg(info,"fired");
          Lvl := Lvl-1;
        }
      };
      -- logMsg(info,"grabbed");
    };
    
    release() do {
      sync(lock){
        Lvl := Lvl+1;
        -- logMsg(info,"released");
      }
    }
  }
}
    